<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <script>
        window.checkCounts = null;/*用户审批消息个数*/
        window.checked = null/*判定用户是否已浏览过审批消息*/
    </script>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <%--使页面外联图片顺利加载--%>
    <meta name="referrer" content="no-referrer">
    <title>实验室资源申请平台</title>
    <%--各种资源引入--%>
    <%--这里有一个巨坑：request.getRequestDispatcher 页面跳转会引起样式，js等外部丢失。所以不要用相对路径，一定用绝对路径引入文件--%>
    <% String path = request.getContextPath();%>
    <link rel="icon" href="<%=path%>/images/logo.ico" type="image/x-icon">
    <link rel="stylesheet" href="<%=path%>/layui/css/layui.css">
    <link rel="stylesheet" href="<%=path%>/css/swiper-bundle.min.css">
    <link rel="stylesheet" href="<%=path%>/css/introduce.css">
    <script src="<%=path%>/js/swiper-bundle.min.js"></script>
    <script src="<%=path%>/layui/layui.js" type="text/javascript"></script>
    <script src="<%=path%>/jquery-3.4.1.js" type="text/javascript"></script>

    <script type="text/javascript">
        function init_head(local) {
            /*未登录状态下的访问拦截及初始密码强改*/
            $.ajax({
                type:"POST",
                url:"${pageContext.request.contextPath}/login.do",
                data:{method:"getRootMsg"},
                dataType:"json",
                success:function (data) {
                    if (data !=null && data.haveSession=="no"){
                        window.location.href='../youShouldLogin.jsp';
                    }else if (data!=null && data.from==2){
                        window.location.href='../error.jsp';
                    }else {
                        /*初始密码强改*/
                        let changePwd = sessionStorage.getItem("changePwd");
                        if (changePwd=='true' && data.pwd === "5ef117d95ed7db0731d8823334218510"){
                            window.location.href="<%=path%>/jsp/user/personal.jsp";
                            sessionStorage.setItem("changePwd",false);
                        }else if (changePwd=='false' && data.pwd==='5ef117d95ed7db0731d8823334218510'){
                            layer.alert('首次登录，请修改初始密码');
                        }
                    }
                }
            })
            /*获取checkCount值，用以产生user端弹窗*/
            checked=sessionStorage.getItem("checked");
            checkCounts=sessionStorage.getItem("checkCounts");
            if (checked==null || checked==undefined){
                $.ajax({
                    type: 'POST'
                    ,url: '${pageContext.request.contextPath}/jsp/apply.do?method=getCheckCount'
                    ,dataType: 'json'
                    ,success:function (data) {
                        if (data.checkCount > 0){
                            sessionStorage.setItem("checked","no");
                            sessionStorage.setItem("checkCounts",data.checkCount);
                            $('#redPoint').attr("class",'layui-badge');
                            /*红点显示*/
                            document.getElementById('redPoint').innerText=data.checkCount;
                            show(data.checkCount);//弹出提示框
                        }else {
                            sessionStorage.setItem("checked","no");
                            sessionStorage.setItem("checkCounts","0");
                        }
                    }
                })
            }else if (checked === "no" && checkCounts != "0" ){
                $('#redPoint').attr("class",'layui-badge');
                /*红点显示*/
                document.getElementById('redPoint').innerText=checkCounts;
                show(sessionStorage.getItem("checkCounts"));
            }

            /*针对不同页面的初始化*/
            if (pageName() == 'personal'){
                $.ajax({
                    type:'POST'
                    ,url:'${pageContext.request.contextPath}/jsp/user.do?method=getPersonalData'
                    ,dataType:'json'
                    ,success:function (data) {
                        if (data!=null){
                            $('#userCode').attr("placeholder",data.userCode);
                            $('#userName').attr("placeholder",data.userName);
                        }
                    }
                })
            }
        }
        /*获取当前界面的名称*/
        function pageName() {
            var a = location.href;
            var b = a.split("/");
            var c = b.slice(b.length-1, b.length).toString(String).split(".");
            return c.slice(0, 1);
        }
    </script>
    <%--申请审批结果提示--%>
    <script type="text/javascript">
        function show(checkCount) {
            //弹窗
            layer.open({
                type: 1
                ,title:"<i class='layui-icon' style='color: #ff0000'>&#xe617;</i>申请结果提示"
                ,offset: ['61.8%','80.8%']
                ,content: '<div style="padding:30px 30px ">您有 <span style="color: red">'+checkCount+'</span> 条申请已经被审批</br>请进入“申请进度查询”模块，查询结果</div>'
                ,btn:'进入查询'
                ,btnAlign: 'c' //按钮居中
                ,shade: 0 //不显示遮罩
                ,yes:function () {
                    sessionStorage.setItem("checked","yes");
                    window.location.href="<%=path%>/jsp/user/progress.jsp";
                }
            });
        }
    </script>

</head>
<body class="layui-layout-body" onload="init_head();">
<div class="layui-layout layui-layout-admin">

    <%--head--%>
    <div class="layui-header">
        <div class="layui-logo" style="color: white;"><img src="<%=path%>/images/LMS_main.png" alt="" style="margin: 3%;">实验室资源申请平台</div>
    </div>

    <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
    <div class="layui-side layui-bg-white">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/jsp/user.do?method=getLabList&local=introduce&from=user"><i class="layui-icon">&#xe670;  实验室概况介绍</i></a></li>
                <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/jsp/user.do?method=getLabList&local=apply"><i class="layui-icon">&#xe6b2;  实验室申请</i></a></li>
                <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/jsp/user/progress.jsp"><i class="layui-icon">&#xe615; 申请进度查询</i><span id="redPoint"></span></a></li>
                <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/jsp/user/personal.jsp"><i class="layui-icon">&#xe770; 个人中心</i></a></li>
                <li class="layui-nav-item" id="exit"><a href="${pageContext.request.contextPath}/jsp/logout.do"><i class="layui-icon">&#xe623; 退出系统</i></a></li>

            </ul>
        </div>
    </div>
        <script type="text/javascript">
            $('#exit').on('click', function () {
                sessionStorage.removeItem("checkCounts");
                sessionStorage.removeItem("checked");
            })
        </script>
